package org.wx.thread.thread;

import lombok.SneakyThrows;

/**
 * @description:
 * @author: wangxun
 * @createDate: 2021/11/26
 * @version: 1.0
 */
public class VolatileTest {
    public  int i ;

    public synchronized void add(){
        i++;
    }
    @SneakyThrows
    public static void main(String[] args) {
        VolatileTest volatileTest = new VolatileTest();
        for (int i = 0; i < 1000; i++) {
            new Thread(()->{
                for (int j = 0; j < 1000; j++) {
                    volatileTest.add();
                }
               }).start();
        }

        Thread.sleep(3000);
        System.out.println(volatileTest.i);
    }
}
